package com.woniuxy.util;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author dingpf
 * @version 1.0
 * @description
 * @create 2025/5/7 11:30
 */
public class StreamTest {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("2", "5", "3","3", "4", "7");
        //用stream对集合操作

        //1：用创建操作流化集合
        //对集合流化
      //  Stream<String> stream = list.stream();
        //对数组流化
       // String[] arr = {};
       // Stream<String> stream1 = Arrays.stream(arr);
        //用Stream本身流化工具
        //Stream<String> stream2 = Stream.of("1", "2", "3");

        //2：用中间操作对集合处理（有很多次）
        //Stream<String> stream1 = stream.distinct();
        //Stream<String> stream2 = stream1.filter(e -> Integer.valueOf(e) >= 5);

        //3：用终止操作输出结果（只有一次）
       // List<String> collect = stream2.collect(Collectors.toList());
       // collect.forEach(e -> System.out.println(e));

//
        List<String> collect1 = list.stream()
                                .distinct()
                                .peek( e -> System.out.println(e))
                                .filter(e -> Integer.valueOf(e) >= 5)
                                .collect(Collectors.toList());


    }
}
